package com.zbkj.business.sys.reservationRecord;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import com.zbkj.business.sys.reservation.ExamReservationDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 预约记录表
 * @create: 2025-03-25 15:20:55
 **/
@Service("examReservationRecord")
@Slf4j
public class ExamReservationRecordService{

    @Resource
    ExamReservationRecordDao examReservationRecordDao;

    @Resource
    ExamReservationDao examReservationDao;
    /**
     * 添加预约记录表,获取id数据
     *
     * @param cdoRequest - create_by:创建者
     *                   - create_date:创建时间
     *                   - del_flag:删除标记（0：正常；1：删除）
     *                   - id:编号
     *                   - record_date:时间段
     *                   - record_name:名称
     *                   - remarks:备注信息
     *                   - update_by:更新者
     *                   - update_date:更新时间
     * @return
     * @author 
     * @create: 2025-03-25 15:20:55
     */
    @OpenApi
    public Return addExamReservationRecord(CDO cdoRequest) {
        examReservationRecordDao.addExamReservationRecord(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新预约记录表数据
     *
     * @param cdoRequest - create_by:创建者
     *                   - create_date:创建时间
     *                   - del_flag:删除标记（0：正常；1：删除）
     *                   - id:编号
     *                   - record_date:时间段
     *                   - record_name:名称
     *                   - remarks:备注信息
     *                   - update_by:更新者
     *                   - update_date:更新时间
     * @return
     * @author 
     * @create: 2025-03-25 15:20:55
     */
    @OpenApi
    public Return updateExamReservationRecordById(CDO cdoRequest) {
        int affectedRows = examReservationRecordDao.updateExamReservationRecordById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，删除预约记录表数据
     *
     * @param cdoRequest - id:编号
     * @return
     * @author 
     * @create: 2025-03-25 15:20:55
     */
    //@OpenApi
    public Return deleteExamReservationRecordById(CDO cdoRequest){
        int affectedRows = examReservationRecordDao.deleteExamReservationRecordById(cdoRequest.getString("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除预约记录表数据
     *
     * @param cdoRequest
     * @return
     * @author 
     * @create: 2025-03-25 15:20:55
     */
    //@OpenApi
    public Return deleteExamReservationRecord(CDO cdoRequest) {
        int affectedRows = examReservationRecordDao.deleteExamReservationRecord(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取预约记录表数据
     *
     * @param cdoRequest - id:编号
     * @return
     * @author 
     * @create: 2025-03-25 15:20:55
     */
    @OpenApi
    public Return getExamReservationRecordById(CDO cdoRequest) {
        CDO cdoMapperResult = examReservationRecordDao.getExamReservationRecordById(cdoRequest.getString("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取预约记录表数据
     *
     * @param cdoRequest - id:编号
     * @return
     * @author 
     * @create: 2025-03-25 15:20:55
     */
    @OpenApi
    public Return getExamReservationRecord(CDO cdoRequest) {
        CDO cdoMapperResult = examReservationRecordDao.getExamReservationRecord(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取预约记录表数据列表
     *
     * @param cdoRequest
     * @return
     * @author 
     * @create: 2025-03-25 15:20:55
     */
    @OpenApi
    public Return getExamReservationRecordList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = examReservationRecordDao.getExamReservationRecordList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = examReservationRecordDao.getExamReservationRecordListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取预约记录表数据列表
     *
     * @param cdoRequest - id:编号
     * @return
     * @author 
     * @create: 2025-03-25 15:20:55
     */
    @OpenApi
    public Return getExamReservationRecordListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = examReservationRecordDao.getExamReservationRecordListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = examReservationRecordDao.getExamReservationRecordListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
